package com.xpec.canaan.util;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;

/**
 * use HashTable recorder element
 * @author Wilson Shih
 *
 */
public class TableElementRecorder {
	
	/**
	 * constructor
	 * 
	 */
	public TableElementRecorder()
	{
		m_elementRecorder = new Hashtable<String, String>();
	}
	
	public boolean addElements(String name, String code)
	{
		if( m_elementRecorder.contains(name) )
		{
			return false;
		}
		
		m_elementRecorder.put(name, code);
		return true;
	}
	
	public boolean dumpToFile(FileOutputRecorder recorder)
	{
		if( null == recorder )
		{
			return false;
		}
		
		Set<String> set = m_elementRecorder.keySet();
		Iterator<String> itr = set.iterator();
		while( itr.hasNext() )
		{
			String key = itr.next();
			recorder.writeIntoFile(key + ":" + m_elementRecorder.get(key)+"\r\n");
		}
		recorder.closeRecorder();
		return true;
	}
	
	// key File name, element MD5 code
	private Hashtable<String, String> m_elementRecorder;
}
